1542A - Odd Set - CodeForces Solution


math *800

Please click on ads to support us..

Python Code:

tt=int(input())
for i in range(tt):
    n=int(input())
    user_list=input().split()
    l=[]
    for i in user_list:
        l.append(int(i))
    o=0
    for i in l:
        if i%2==1:
            o+=1 
        else:
            o-=1 
    if o==0:
        print("YES")
    else:
        print("NO")

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n;
        cin>>n;
        int *a = new int[2 * n];
        for(int i=0;i< 2*n;i++)
        {
            cin>>a[i];
        }
        int nCountOdd = 0, nCountEven = 0;
        for(int i=0;i< 2*n;i++)
        {
            if(a[i] %2 ==0)
            {
                nCountEven ++;
            }
            else 
            {
                nCountOdd ++;
            }
        }
        
        if(nCountOdd == nCountEven)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
        delete []a;
    }
}


Comments

Submit
0 Comments
More Questions

Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!